# -*- coding: utf-8 -*-
import datetime
import os
import sys
import threading
import json

import main2
from Apple import Apple
from Fruit import Fruit
from MyThread import MyThread
from test import test2

a = 1.1


def sysout(pid):
    print("pid = " + str(pid))
    print("pid = " + str(type(a)))
    print("年 = " + str(datetime.datetime.now().year))
    print("年 = ", datetime.datetime.now().year)


if __name__ == "__main__":
    sysout(1207)

    print("################类和对象################")
    fruit = Fruit("red")
    print(fruit)
    print(fruit._size)
    # print(fruit.__taste) # 报错 类属性
    # print(Fruit.__taste) # 报错 私有的
    print(fruit._Fruit__taste)
    print(fruit.getTaste())
    print(fruit.getTaste2)

    print("################继承################")
    apple = Apple("green")
    print(apple)
    print(apple.color)
    print(Apple.color)
    print(Fruit.color)

    print("################模块################")
    print(sys.path)
    print(main2.a)
    print(test2.a)

    print("################文件操作################")
    # with open("Apple.py", "a", encoding="utf-8") as file:
    #     file.write('\nprint("年 = " + str(datetime.now().year))')

    with open("Apple.py", "r", encoding="utf-8") as file:
        lines = file.readlines()
        for line in lines:
            print(line)

    print("################目录操作################")
    print(os.name)
    print(os.linesep)
    print(os.getcwd())

    print("################线程################")
    thread = threading.Thread(target=sysout(0))
    thread.start()
    thread.join()

    myThread = MyThread()
    myThread.start()
    myThread.join()

    print("主线程结束")

    print("################异常################")


    def division(aa, bb):
        if bb == 0:
            raise Exception("除数为0")
        else:
            result = aa / bb
            print(result)


    try:
        division(1, 0)
    except Exception as e:
        print(e)
    finally:
        print("关闭资源")

    print("################命令行操作################")
    result = os.popen("adb devices").readlines()
    for line in result:
        print(line)

    print("################网络操作，见：hotwords_contact.py################")

    print("################json操作################")
    jsonStr = '{"name":"lp","age":33}'
    apple = json.loads(jsonStr)
    print(type(apple), apple)
    jsonStr = json.dumps(apple)
    print(type(jsonStr), jsonStr)
